﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Account.aspx.cs" Inherits="Account" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Edit ListView</title>
<style type="text/css">

    .account
    {
       border: solid 1px black;
       padding:5px;
       margin:3px; 
    }

    .edit
    {
        background-color:Yellow;
    }

</style>    
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ListView 
            ID="lstAccount"
            DataSourceId="srcAccount"
            DataKeyNames="id"
            runat="server">
            <LayoutTemplate>
                <asp:Placeholder 
                    id="itemPlaceholder"
                    runat="server" />
            </LayoutTemplate>
            <ItemTemplate>
                <div class="account">
                <strong><%# Eval("username") %></strong>
                <br />
                <em><%# Eval("password") %></em>
                <br />
                <asp:LinkButton
                    id="lnkEdit"
                    Text="{Edit}"
                    CommandName="Edit"
                    Runat="server" />
                <asp:LinkButton
                    id="lnkDelete"
                    Text="{Delete}"
                    CommandName="Delete"
                    OnClientClick="return confirm('Delete this account?')"
                    Runat="server" />
                </div>
            </ItemTemplate>
            <EditItemTemplate>
                <div class="account edit">
                <asp:Label
                    id="lblUsername"
                    Text="User name:"
                    AssociatedControlID="txtUsername"
                    Runat="server" />
                <br />
                <asp:TextBox
                    id="txtUsername"
                    Text='<%# Bind("username") %>'
                    Runat="server" />    
                
                <br /><br />

                <asp:Label
                    id="lblPassword"
                    Text="Password:"
                    AssociatedControlID="txtPassword"
                    Runat="server" />
                <br />
                <asp:TextBox
                    id="txtPassword"
                    Text='<%# Bind("password") %>'
                    Runat="server" />    
                
                <br /><br />
                <asp:LinkButton
                    id="lnkUpdate"
                    Text="Save"
                    CommandName="Update"
                    Runat="server" />
               <asp:LinkButton
                    id="lnkCancel"
                    Text="Cancel"
                    CommandName="Cancel"
                    Runat="server" /> 
                </div>
            </EditItemTemplate>
        </asp:ListView>
    
        <asp:SqlDataSource
            id="srcAccount"
            SelectCommand="SELECT id, username, password FROM account"
            UpdateCommand="Update account SET username=@username, password=@password WHERE id=@id"            
            DeleteCommand="Delete account WHERE id=@id"    
            ConnectionString='<%$ ConnectionStrings:Liwubang %>'
            Runat="server" />
    
    </div>
    </form>
</body>
</html>